package com.zpp.enums;


import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * @Author: lzqing
 * @Description: 策略枚举类
 * @Date: Created in 2021/6/6
 */
public enum Strategy {

  FAST {
    @Override
    void run() {
      System.out.println("FAST");
    }
  },
  NORMAL {
    @Override
    void run() {
      System.out.println("NORMAL");
    }
  },

  SMOOTH {
    @Override
    void run() {
      System.out.println("SMOOTH");
    }
  },

  SLOW {
    @Override
    void run() {
      System.out.println("SLOW");
    }
  };

  private static final Map<String, Strategy> MAP = new HashMap<>();

  static {
    for (Strategy e : values()) {
      MAP.put(e.code, e);
    }
  }

  private String code;

  Strategy() {
  }

  Strategy(String code) {
    this.code = code;
  }

  public static Strategy valueOfName(String code) {
    return MAP.get(code);
  }

  public static void main(String[] args) {
    Strategy strategy = Strategy.valueOf("SLOW");
    valueOfName("SLOW").run();
    strategy.run();
  }

  abstract void run();

  public String toLocale() {
    if (Locale.CHINA.equals(Locale.getDefault())) {
      return code;
    }
    return toString();
  }
}
